package com.agile.major.service.impl;

import com.agile.major.domain.BaseMajor;
import com.agile.major.domain.LastGraduateEmployment;
import com.agile.major.repository.BaseMajorRepository;
import com.agile.major.repository.LastGraduateEmploymentRepository;
import com.agile.major.service.LastGraduateEmploymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Service Implementation for managing LastGraduateEmployment.
 */
@Service
@Transactional
public class LastGraduateEmploymentServiceImpl implements LastGraduateEmploymentService{

    private final Logger log = LoggerFactory.getLogger(LastGraduateEmploymentServiceImpl.class);

    private final LastGraduateEmploymentRepository lastGraduateEmploymentRepository;
    private BaseMajorRepository baseMajorRepository;
    public LastGraduateEmploymentServiceImpl(LastGraduateEmploymentRepository lastGraduateEmploymentRepository,BaseMajorRepository baseMajorRepository) {
        this.lastGraduateEmploymentRepository = lastGraduateEmploymentRepository;
        this.baseMajorRepository = baseMajorRepository;
    }

    /**
     * Save a lastGraduateEmployment.
     *
     * @param lastGraduateEmployment the entity to save
     * @return the persisted entity
     */
    @Override
    public LastGraduateEmployment save(LastGraduateEmployment lastGraduateEmployment) {
        log.debug("Request to save LastGraduateEmployment : {}", lastGraduateEmployment);
        return lastGraduateEmploymentRepository.save(lastGraduateEmployment);
    }

    /**
     *  Get all the lastGraduateEmployments.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<LastGraduateEmployment> findAll(Pageable pageable) {
        log.debug("Request to get all LastGraduateEmployments");
        return lastGraduateEmploymentRepository.findAll(pageable);
    }

    /**
     *  Get one lastGraduateEmployment by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public LastGraduateEmployment findOne(Long id) {
        log.debug("Request to get LastGraduateEmployment : {}", id);
        return lastGraduateEmploymentRepository.findOne(id);
    }

    /**
     *  Delete the  lastGraduateEmployment by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete LastGraduateEmployment : {}", id);
        lastGraduateEmploymentRepository.delete(id);
    }

    @Override
    public List<LastGraduateEmployment> getLastGraduateEmploymentByMajorAndYear(Long baseMajorId, String year) {
        BaseMajor major = baseMajorRepository.findOne(baseMajorId);
        if (major == null) {
            log.debug("Request to get FreshGraduateEmployment : {}", major);
        }
        return lastGraduateEmploymentRepository.findLastGraduateEmploymentByBaseMajorAndDataYear(major,year);
    }
}
